package com.wanyu.video.nio.zero.copy;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class NIOZeroCopyServer {


    public static void main(String[] args) throws Exception{
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.socket().bind(new InetSocketAddress(6666));
        ByteBuffer byteBuffer = ByteBuffer.allocate(4096);
        int size = 0;
        while (true) {
            SocketChannel socketChannel = serverSocketChannel.accept();
            int readCount = 0;
            while (-1 != readCount) {
                try {
                    readCount = socketChannel.read(byteBuffer);
                    size += readCount;
                } catch (Exception e) {
                    break;
                }
                byteBuffer.rewind();
            }
            System.out.println("上传文件大小 ：" + size);
        }

    }
}
